/*
 * Copyright © 2024-2025 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#include "../include/string.h"

/**
 * @brief Transform a string into a locale-specific form that can be used for comparison.
 *
 * @param dest The destination string buffer.
 * @param src The source string.
 * @param n The size of the destination buffer.
 * @return The length of the transformed string.
 */
size_t Sstrxfrm(char *dest, const char *src, size_t n) {
    size_t len = 0;  

    while (len < n - 1 && *src) {
        *dest++ = *src++;  
        len++;  
    }  
    
    if (n > 0)
        *dest = '\0';
    
    while (*src) {
        len++;  
        src++;  
    }  

    return len;
}  